package cn.hairui.blog.dao;

import cn.hairui.blog.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户信息表 Mapper 接口
 * </p>
 *
 * @author laoganbu
 * @since 2020-04-07
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("SELECT\n" +
            "    id,\n" +
            "    account,\n" +
            "    nickname,\n" +
            "    name,\n" +
            "    sex,\n" +
            "    prophoto,\n" +
            "    case when email is null then '' else email end as email,\n" +
            "    mobile,\n" +
            "    type,\n" +
            "    status,\n" +
            "    last_login_time AS lastLoginTime\n" +
            "FROM\n" +
            "    USER\n" +
            "ORDER BY\n" +
            "    id DESC")
    List<Map> list();

    @Update("update user set status=#{status} where account=#{account}")
    void updateStatusByAccount(String account, String status);

    @Select("select * from user where binary account=#{account} and password=#{password}")
    User getByAccountAndPassword(String account, String password);

    @Select("select * from user where binary account=#{account}")
    User getByAccount(String account);

    @Select("select* from user where binary email=#{email}")
    User getByEmail(String email);
}
